package org.gruposp2p.dnie.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gruposp2p.dnie.model.xmladapter.DNIeDocumentToSignAdapter;
import org.gruposp2p.dnie.model.xmladapter.DNIeUserAdapter;
import org.gruposp2p.dnie.model.xmladapter.DateAdapter;

/**
 *
 * @author jj
 */
@XmlType
@XmlRootElement(name = "DNIeSignedDocument")
@XmlAccessorType(XmlAccessType.NONE)
@Entity
@Table(name = "DNIESIGNEDDOCUMENT", catalog = "DNIE")
@NamedQueries({
    @NamedQuery(name = "DNIeSignedDocument.findAll", query = "SELECT d FROM DNIeSignedDocument d"),
    @NamedQuery(name = "DNIeSignedDocument.findById", query = "SELECT d FROM DNIeSignedDocument d WHERE d.id = :id"),
    @NamedQuery(name = "DNIeSignedDocument.findByDate", query = "SELECT d FROM DNIeSignedDocument d WHERE d.date = :date")})
public class DNIeSignedDocument implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    @XmlElement
    private Integer id;
    @Basic(optional = false)
    @Column(name = "DATE", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    @XmlElement
    @XmlJavaTypeAdapter(DateAdapter.class)
    private Date date;
    @Basic(optional = false)
    @Lob
    @Column(name = "XMLDSIGDATA", nullable = false)
    @XmlElement
    private String xmlDsigData;
    @JoinColumn(name = "DNIEDOCUMENTTOSIGN_ID", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    @XmlElement
    private DNIeDocumentToSign dnieDocumentToSignId;
    @JoinColumn(name = "DNIEUSER_ID", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    @XmlElement
    @XmlJavaTypeAdapter(DNIeUserAdapter.class)
    private DNIeUser dnieUserId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "dnieSignedDocumentId")
    @XmlElementWrapper(name = "signedOptions")
    @XmlElement(name = "option", nillable=true)
    private Collection<DNIeSignedDocumentOptionSelected> dnieSignedDocumentOptionSelectedCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "dnieSignedDocumentId")
    @XmlElementWrapper(name = "comments")
    @XmlElement(name = "comment", nillable=true)
    private Collection<DNIeSignedDocumentComment> dnieSignedDocumentCommentCollection;

    public DNIeSignedDocument() {
    }

    public DNIeSignedDocument(Integer id) {
        this.id = id;
    }

    public DNIeSignedDocument(Integer id, Date date, String data) {
        this.id = id;
        this.date = date;
        this.xmlDsigData = data;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getXmlDsigData() {
        return xmlDsigData;
    }

    public void setXmlDsigData(String data) {
        this.xmlDsigData = data;
    }

    public DNIeDocumentToSign getDnieDocumentToSignId() {
        return dnieDocumentToSignId;
    }

    public void setDnieDocumentToSignId(DNIeDocumentToSign dnieDocumentToSignId) {
        this.dnieDocumentToSignId = dnieDocumentToSignId;
    }

    public DNIeUser getDnieUserId() {
        return dnieUserId;
    }

    public void setDnieUserId(DNIeUser dnieUserId) {
        this.dnieUserId = dnieUserId;
    }

    public Collection<DNIeSignedDocumentOptionSelected> getDNIeSignedDocumentOptionSelectedCollection() {
        return dnieSignedDocumentOptionSelectedCollection;
    }

    public void setDNIeSignedDocumentOptionSelectedCollection(Collection<DNIeSignedDocumentOptionSelected> dnieSignedDocumentOptionSelectedCollection) {
        this.dnieSignedDocumentOptionSelectedCollection = dnieSignedDocumentOptionSelectedCollection;
    }

    public Collection<DNIeSignedDocumentComment> getDNIeSignedDocumentCommentCollection() {
        return dnieSignedDocumentCommentCollection;
    }

    public void setDNIeSignedDocumentCommentCollection(Collection<DNIeSignedDocumentComment> dnieSignedDocumentCommentCollection) {
        this.dnieSignedDocumentCommentCollection = dnieSignedDocumentCommentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DNIeSignedDocument)) {
            return false;
        }
        DNIeSignedDocument other = (DNIeSignedDocument) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "dniedatabasemodel01.DNIeSignedDocument[id=" + id + "]";
    }

}
